/**
 * 操作类型
 * @type {{"1": string, "2": string, "3": string, "4": string, "5": string, "6": string, "7": string, "8": string, "9": string, "10": string, "11": string, "12": string, "13": string, "14": string, "15": string, "16": string, "17": string, "18": string, "19": string, "20": string, "21": string, "22": string, "23": string, "24": string, "25": string, "26": string, "27": string, "28": string, "29": string, "30": string, "31": string, "32": string, "33": string, "34": string, "35": string, "36": string, "37": string, "38": string, "39": string, "40": string, "41": string, "42": string, "43": string, "44": string, "45": string, "46": string, "47": string, "48": string, "49": string, "50": string, "51": string}}
 */
var operType = {
    1: '新增', 2: '修改', 3: '下载图片', 4: '证书费用申请', 5: '费用申请通过', 6: '费用申请不通过', 7: '出库', 8: '入库', 9: '超期', 10: '预定', 11: '匹配', 12: '挂靠', 13: '取消预定', 14: '取消匹配',
    15: '取消挂靠', 16: '取消预约', 17: '分配', 18: '证书匹配', 19: '申请退单', 20: '备注', 21: '打电话', 22: '接收', 23: '退回', 24: '转单', 25: '档案绑定', 26: '移交', 27: '生产暂停', 28: '生产费用申请', 29: '添加协单',
    30: '取消协单', 31: '创建工单', 32: '审核通过', 33: '驳回', 34: '变更审核人', 35: '撤回', 36: '生产完结', 37: '强制完结', 38: '结项', 39: '停用', 40: '启用', 41: '复制指导价', 42: '复制流程', 43: '更新节点',
    44: '退单恢复办理', 45: '暂停恢复办理', 46: '退单审核通过', 47: '退单审核驳回', 48: '预约', 49: '证书移交', 50: '删除', 51: '查看', 52: "资质申请转让", 53: "资质转让变更审核人", 54: "资质转让审核", 55: "添加管理系统配置", 56: "修改管理系统配置", 57: "修改单个预警值",
    58: '添加指导价', 59: '修改指导价', 60: '复制指导价', 61: '导出指导价', 62: '导出查询证书', 63: '导出资质审核驳回记录', 64: '导出资质审核通过记录'
};

/**
 * 按钮倒计时
 * countDount 倒计时数
 */
function settime(obj, countDown, btnVal) {
    if (countDown == 0) {
        obj.attr('disabled', false);
        //obj.removeattr("disabled");
        obj.val(btnVal);
        countDown = 10;
        return;
    } else {
        obj.attr('disabled', true);
        obj.val("重新发送(" + countDown + ")");
        countDown--;
    }
    setTimeout(function () {
            settime(obj, countDown, btnVal);
        }
        , 1000)
}


// 清空搜索
function cleanSearch() {
    var $s = $('.titleSearch');
    $s.find('input').val('');
    $s.find('select').val('').trigger("change");
    $s.find('input').attr("data-id", '');
    // $s.find("option[value='']").attr("selected",true);
}


// 隐藏电话
function hidePhone(phoneStr) {
    if (null == phoneStr || undefined == phoneStr) {
        return
    }
    ;
    var length = phoneStr.length;
    if (length == 0) {
        return "";
    }
    if (length == 1) {
        return "*";
    }
    if (length > 10) {
        return phoneStr.substr(0, 3) + "****" + phoneStr.substr(length - 4, length);
    }
    if (length <= 10 && length > 3) {
        return phoneStr.substr(0, length - 4) + "****";
    }
    return phoneStr.substr(0, 1) + "*";

}

/**
 * 列表操作
 * @param obj 需要刷新的table
 * @param operation 操作   reloadFalse getCheck reload
 */
function search(obj, operation) {
    $(obj).dataTableExtend(operation);
}


/**
 * 根据资质类型查资质名称
 * typeObj:资质类型的id
 * obj:资质名称(证书专业)
 * generalType:大类型(证书或资质)编码
 * width 二级联动框的宽度
 */
function findCertificateName(width, typeObj, obj, generalType) {
    var selectStr = $(obj);
    var parentId = $(typeObj + ' option:selected').val();
    selectStr.empty();
    var optionStr = '<option value="">全部</option>';
    $.post(sysInfo.basePath + "/zs/certificate_type/get_certificate_type.do", {
        parentId: parentId,
        generalType: generalType
    }, function (re) {
        if (re.code == 0) {
            var params = re.data;
            for (var i = 0; i < params.length; i++) {
                optionStr += '<option value="' + params[i].id + '" data-level="' + params[i].certificateLevel + '">' + params[i].certificateName + '</option>';
            }
            selectStr.append(optionStr);
            $(obj).select2({
                placeholder: "请选择",
                allowClear: false,
                width: width,
                language: "zh-CN"
            });
        } else {
            DGG.Errors(re.msg);
        }

    })
}

//根据资质名称产资质等级
function findCertificateLevel(obj, levelObj) {
    var selectStr = $(levelObj);
    var levelStrs = $(obj + " option:selected").attr("data-level");
    selectStr.empty();
    if (!checkIsEmpty(levelStrs)) {
        var leves = levelStrs.split(",");
        var optionStr = '<option value="">全部</option>';
        for (var i = 0; i < leves.length; i++) {
            optionStr += '<option>' + leves[i] + '</option>';
        }
        selectStr.append(optionStr);
        $(levelObj).select2({
            placeholder: "请选择",
            allowClear: true,
            width: "190px",
            language: "zh-CN"
        });
        selectStr.removeAttr("disabled");
    } else {
        selectStr.attr("disabled", "true");
    }
}

//导出excell  url
function export_table(url, params) {
    var form = $("<form>");//定义一个form表单
    form.attr("style", "display:none");
    form.attr("target", "_self");
    form.attr("method", "post");
    form.attr("accept-charset", "utf-8");
    if (params) {
        jQuery.each(params, function (i, val) {
            var $input = $(document.createElement('input'));
            $input.attr('name', i).val(val != null ? val : '');
            form.append($input);
        });
    }
    form.attr("action", sysInfo.basePath + url);
    $("body").append(form);//将表单放置在web
    form.submit();//表单提交
}

// 获取搜索数据
function getSearchData(obj) {
    return obj.serializeObject();
}

/**
 * 预警标签
 * @param expiration 到期时间
 * @param dangerTags 危险标签 （过期）
 * @param securityLabel 安全标签 （快过期）
 * @returns {string}
 */
function addLabel(expiration, dangerTags, securityLabel) {
    if (!expiration) {
        return "";
    }
    var expirationDate = new Date(expiration.replace(/-/g, "/"));
    var now = new Date();
    now.setHours(expirationDate.getHours());
    now.setMinutes(expirationDate.getMinutes());
    now.setSeconds(expirationDate.getSeconds());
    var time = Date.parse(now);
    var expirationTime = Date.parse(expiration);
    var day = Math.floor((expirationTime - time) / (1000 * 60 * 60 * 24));
    var tags = dangerTags.substring(0, 2);
    if (day == 0) {
        return "<span style='color:#008000;'>" + tags + "今天到期" + "</span>";
    } else if (day > 0) {
        return "<span style='color:#008000;'>" + securityLabel + day + "天</span>";
    } else {
        return "<span style='color:#FF0000;'>" + dangerTags + Math.abs(day) + "天</span>";
    }
}

/*隐藏省份证号码*/
function hideIdCard(card) {
    if (null == card || "" === card) {
        return "";
    }
    var length = card.length - 3 - 4;
    var reg = new RegExp("^(\\w{4})\\w{" + length + "}(\\w{3})$");
    return card.replace(reg, '$1***********$2')
}

/*
 * 列表字段超长处理方法
 */

//部分备注信息
function getPartHtml(str) {
    return str.substr(0, showLength) + '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="changeShow(this)"><b>...</b></a>';
}

//全部备注信息
function getTotalHtml(str) {
    return str + '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="changeShow(this)>收起</a>';
}

//切换显示备注信息，显示部分或者全部
function changeShow(obj) {
    var content = $(obj).attr("content");
    if (content != null && content != '') {
        if ($(obj).attr("isDetail") == 'true') {//当前显示的是详细备注，切换到显示部分
            $(obj).attr('isDetail', false);
            $(obj).html(getPartHtml(content));
        } else {//当前显示的是部分备注信息，切换到显示全部
            $(obj).attr('isDetail', true);
            $(obj).html(getTotalHtml(content));
        }
    }
}

function fieldHandle(data, showLength) {
    var result = "";
    if (checkIsEmpty(showLength)) {
        showLength = 200;
    }
    if (checkIsEmpty(data)) {
        if (data.length > showLength) {
            result = data.substr(0, showLength) + '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="changeShow(this)"><b>...</b></a>';
        } else {
            result = data;
        }
    }
    return result;
}

//查看身份证、电话号码
//number:身份证号码或客户id
//type:1、身份证  2、电话号码
//getType:1、生成订单  2、接口获取
function seeNumber(obj, number, type, getType) {
    $.ajax({
        url: sysInfo.basePath + "/rzsc/common/see_number.do",
        data: {number: number, type: type, getType: getType},
        type: "POST",
        dataType: "json",
        success: function (result) {
            if (result.code == 0) {
                var $obj = $(obj).prev();
                var beforeNumber = $obj.html();
                if (type == 2) {
                    number = result.data;
                }
                $obj.html(number);
                $(obj).hide();
                DGG.Layer.message("5秒后自动隐藏", {icon: '2'});
                window.setTimeout(function () {
                    $obj.html(beforeNumber);
                    $(obj).show();
                }, 5000);
                DGG.Layer.message("5秒后自动隐藏", {icon: '2'});
            } else {
                DGG.Layer.message(result.msg, {icon: '2'});
            }
        }
    });
}

/**
 * 根据组织机构id判断选择的组织机构是否是事业部
 * @param orgId
 * @param level
 */
function findOrgInfo(orgId) {
    var isSyb;
    $.ajax({
        url: sysInfo.basePath + "/rzsc/common/find_org_by_id.do",
        async: false,
        data: {orgId: orgId},
        type: "POST",
        dataType: "json",
        success: function (result) {
            if (result.code == 0) {
                var orgInfo = result.data.orgLevel;
                if ("ORG_LEVEL_1" == orgInfo) {
                    isSyb = true;
                }else {
                    isSyb = false;
                }
            }
        }
    });
    return isSyb;
}